<template>
	<view class="context">
		<uv-empty v-show="list.length === 0" mode="address"></uv-empty>
		<view @click="setSelect(item)" class="address_item" v-for="(item,index) in list" :key="item.id">
			<view class="address_text">
				<view class="title_tex">
					<text class="title_item">{{ item.title }}</text>
					<text>{{ item.address }}</text>
				</view>
				<view class="phone">{{ item.name }} {{ item.tel }}</view>
			</view>
			<image @click.stop="goAdd(item)" src="@/static/image/home/edit.png" mode=""></image>
		</view>

		<view @click="goAdderss" :style="{ 'bottom' : $getBottomHight() + 20 + 'px'}" class="address_btn">添加地址</view>
	</view>
</template>

<script>
	import { getAddressList } from '@/api/home.js'
	export default {
		data() {
			return {
				list: [],
				isClik: false
			}
		},
		onLoad(option) {
			if (option.item) {
				this.isClik = true
			}
		},
		onShow() {
			this.addressList()
		},
		methods: {
			setSelect(item) {
				if (!this.isClik) return;
				uni.$emit('address', item)
				uni.navigateBack()
			},
			goAdd(item) {
				uni.navigateTo({
					url: `/pages/addAddress/addAddress?item=${encodeURIComponent(JSON.stringify(item))}`
				})
			},
			goAdderss() {
				uni.navigateTo({
					url: '/pages/addAddress/addAddress'
				})
			},
			addressList() {
				getAddressList().then(res => {
					if (res.code === 1) {
						this.list = res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.address_btn {
		position: fixed;
		right: 30rpx;
		left: 30rpx;
		padding: 20rpx 0;
		text-align: center;
		font-size: 30rpx;
		border-radius: 45rpx;
		color: #333;
		background-color: #f5c71c;
	}

	.context {
		width: 100%;
		position: absolute;
		top: 0;
		bottom: 0;
		background-color: #fff;
	}

	.address_item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 25rpx 20rpx;
		border-bottom: 1rpx solid #f7f7f7;
		font-size: 28rpx;

		.address_text {
			width: 70%;
			.title_tex {
				display: flex;
				align-items: center;
				.title_item {
					font-weight: 600;
					padding-right: 20rpx;
					font-size: 30rpx;
				}
			}
			.phone {
				font-size: 26rpx;
				color: #909399;
				margin-top: 10rpx;
			}
		}

		image {
			width: 40rpx;
			height: 40rpx;
		}
	}
</style>